/* 
 * File:   NetAddress.cpp
 * Author: jacek
 * 
 * Created on 14 kwiecień 2011, 18:46
 */

#include "include/NetAddress.h"
namespace Net {
NetAddress::NetAddress() {
	memset(&address, 0, size);
}

NetAddress::NetAddress(const char* hostname, int port) {
	memset(&address, 0, size);
	address.sin_family = AF_INET;
	address.sin_port = htons(port);
	struct hostent *hn;
	hn = (struct hostent*) gethostbyname(hostname);
	if (hn == NULL)
		throw "Unknwon host name";
	else
		address.sin_addr = *((struct in_addr *) hn->h_addr);
}

NetAddress::NetAddress(const NetAddress& orig) {
	memset(&address, 0, size);
	address = orig.address;
}
void NetAddress::SetAddress(const char* hostname, int port) {
	address.sin_family = AF_INET;
	address.sin_port = htons(port);
	struct hostent *hn;
	hn = (struct hostent*) gethostbyname(hostname);
	if (hn == NULL)
		throw "Unknwon host name";
	else
		address.sin_addr = *((struct in_addr *) hn->h_addr);
}
char* NetAddress::GetAddressIp() {
	return inet_ntoa(address.sin_addr);
}
}
